<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .tex1 {
            outline: none;
        }

        div {
            width: 350px;
            margin: 100px 200px;
        }

        .message {
            display: inline-block;
            font-size: 12px;
            color: #999;
            background: url(images/mess.png) no-repeat left center;
            padding-left: 20px;
        }
        .wrong{
           color: red;
           background: url(images/wrong.png) no-repeat left center;
        }
        .right{
            color: green;
            background: url(images/right.png) no-repeat left center;
        }
    </style>
</head>

<body>
    <input type="text" class="tex1" placeholder="请输入内容">
    <div class="register">
        <input type="password" class="ipt">
        <p class="message">请输入6~16位密码</p>
    </div>
    <script>
        //1.获得失去焦点
        var tex1 = document.querySelector('.tex1');
        tex1.onfocus = function() {
            this.style.backgroundColor = '#ff6700';
        }
        tex1.onblur = function() {
            this.style.backgroundColor = '#fff';
        }

        //2.判断密码
        var ipt = document.querySelector('.ipt');
        var mess = document.querySelector('.message');
        ipt.onblur = function () {
            if(this.value.length < 6 || this.value.length > 16){
                mess.className = 'message wrong';
                mess.innerHTML = '您输入的位数需6~16位!'
            }else{
                mess.className = 'message right';
                mess.innerHTML = '您的输入正确!'
            }
        }
    </script>
</body>

</html>